package agenda;

import java.io.File;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.filechooser.FileNameExtensionFilter;

public class JanelaPerfil extends javax.swing.JFrame {

		/** Creates new form JanelaPerfil */
		public JanelaPerfil() {
			initComponents();
			setDefaultCloseOperation(HIDE_ON_CLOSE);
			setIconImage((new ImageIcon(getClass().getResource("/agenda/logo.png")).getImage()));
			setTitle("Perfil");
		    this.setLocationRelativeTo(null);  
		}

		/**
		 * This method is called from within the constructor to initialize the
		 * form. WARNING: Do NOT modify this code. The content of this method is
		 * always regenerated by the Form Editor.
		 */
		@SuppressWarnings("unchecked")
		// <editor-fold defaultstate="collapsed" desc="Generated Code">
		private void initComponents() {

			JlabelPerfil1 = new javax.swing.JLabel();
			jPanel1 = new javax.swing.JPanel();
			JlabelPerfil = new javax.swing.JLabel();
			JlabelNome = new javax.swing.JLabel();
			JlabelEndereço = new javax.swing.JLabel();
			JlabelData = new javax.swing.JLabel();
			JlabelEmail = new javax.swing.JLabel();
			JlabelTelefone = new javax.swing.JLabel();
			JlabelDescricao = new javax.swing.JLabel();
			jTextFieldNome = new javax.swing.JTextField(Agenda.Usuario.getNome());
			jTextFieldEndereco = new javax.swing.JTextField(Agenda.Usuario
					.getEndereco());
			jTextFieldEmail = new javax.swing.JTextField(Agenda.Usuario.getEmail());
			jTextFieldTelefone = new javax.swing.JTextField(Agenda.Usuario
					.getTelefone());
			jTextAreaDescricao = new javax.swing.JTextArea(Agenda.Usuario
					.getDescricaoUsuario());
			jFormattedTextFieldData = new javax.swing.JFormattedTextField();
			jButtonCancelar = new javax.swing.JButton();
			jButtonSalvar = new javax.swing.JButton();
			jLabelFoto = new javax.swing.JLabel();
			jButtonAlterarFoto = new javax.swing.JButton();

			JlabelPerfil1.setFont(new java.awt.Font("Monotype Corsiva", 0, 24));
			JlabelPerfil1.setText("Perfil");

			setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

			JlabelPerfil.setFont(new java.awt.Font("Monotype Corsiva", 3, 36));
			JlabelPerfil.setText("Perfil do Úsuario");

			JlabelNome.setFont(new java.awt.Font("Times New Roman", 1, 18));
			JlabelNome.setText("Nome:");

			JlabelEndereço.setFont(new java.awt.Font("Times New Roman", 1, 18));
			JlabelEndereço.setText("Endereço:");

			JlabelData.setFont(new java.awt.Font("Times New Roman", 1, 18));
			JlabelData.setText("Data de Nascimento:");

			JlabelEmail.setFont(new java.awt.Font("Times New Roman", 1, 18));
			JlabelEmail.setText("E-mail:");

			JlabelTelefone.setFont(new java.awt.Font("Times New Roman", 1, 18));
			JlabelTelefone.setText("Telefone:");

			JlabelDescricao
					.setFont(new java.awt.Font("Times New Roman", 1, 18));
			JlabelDescricao.setText("Descrição:");

			jFormattedTextFieldData
					.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(
							new javax.swing.text.DateFormatter()));

			jButtonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/ip_icon_02_Cancel.png"))); // NOI18N
			jButtonCancelar.setText("Cancelar");
			jButtonCancelar
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(
								java.awt.event.ActionEvent evt) {
							setVisible(false);
							dispose();
						}
					});

			jButtonSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/agenda/ip_icon_02_Ok.png"))); // NOI18N
			jButtonSalvar.setText("Salvar");
			jButtonSalvar
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(
								java.awt.event.ActionEvent evt) {
							Agenda.Usuario.setDataDeNascimento(jFormattedTextFieldData
									.getText());
							Agenda.Usuario.setDescricaoUsuario(jTextAreaDescricao
									.getText());
							Agenda.Usuario.setEmail(jTextFieldEmail.getText());
							Agenda.Usuario.setEndereco(jTextFieldEndereco.getText());
							Agenda.Usuario.setFotoUsuairo(jLabelFoto.getIcon());
							Agenda.Usuario.setNome(jTextFieldNome.getText());
							Agenda.Usuario.setTelefone(jTextFieldTelefone.getText());
							try {
								Arquivos.salvarObjeto(new File("Usuario.dat"), Agenda.Usuario);
							} catch (Exception e) {
								e.printStackTrace();
							}
							setVisible(false);
							dispose();
						}
					});

			jLabelFoto.setIcon(Agenda.Usuario.getFotoUsuario()); // NOI18N

			jButtonAlterarFoto.setText("Alterar foto");
			jButtonAlterarFoto
					.addActionListener(new java.awt.event.ActionListener() {
						public void actionPerformed(
							java.awt.event.ActionEvent evt) {
							JFileChooser jFileChooser1 = new javax.swing.JFileChooser();
							jFileChooser1.setFileFilter(new FileNameExtensionFilter("JPG","jpg"));
							jFileChooser1.showOpenDialog(null);
							File file = jFileChooser1.getSelectedFile();
							RedimensionarImagem.redimensionaImagem(file,"Usuario."+file.getName().substring(file.getName().lastIndexOf(".")+1,file.getName().length()),121,164);
							Icon icon = new ImageIcon(("Usuario."+file.getName().substring(file.getName().lastIndexOf(".")+1,file.getName().length())));
							jLabelFoto.setIcon(icon);
					    }
					});

			javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
					jPanel1);
			jPanel1.setLayout(jPanel1Layout);
			jPanel1Layout
					.setHorizontalGroup(jPanel1Layout
							.createParallelGroup(
									javax.swing.GroupLayout.Alignment.LEADING)
							.addGroup(
									jPanel1Layout
											.createSequentialGroup()
											.addGroup(
													jPanel1Layout
															.createParallelGroup(
																	javax.swing.GroupLayout.Alignment.LEADING)
															.addGroup(
																	jPanel1Layout
																			.createSequentialGroup()
																			.addContainerGap()
																			.addComponent(
																					jLabelFoto,
																					javax.swing.GroupLayout.PREFERRED_SIZE,
																					121,
																					javax.swing.GroupLayout.PREFERRED_SIZE))
															.addGroup(
																	jPanel1Layout
																			.createSequentialGroup()
																			.addGap(
																					28,
																					28,
																					28)
																			.addComponent(
																					jButtonAlterarFoto)))
											.addGap(18, 18, 18)
											.addGroup(
													jPanel1Layout
															.createParallelGroup(
																	javax.swing.GroupLayout.Alignment.LEADING)
															.addComponent(
																	JlabelDescricao)
															.addGroup(
																	jPanel1Layout
																			.createSequentialGroup()
																			.addGroup(
																					jPanel1Layout
																							.createParallelGroup(
																									javax.swing.GroupLayout.Alignment.LEADING)
																							.addComponent(
																									JlabelEndereço,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									78,
																									javax.swing.GroupLayout.PREFERRED_SIZE)
																							.addComponent(
																									JlabelNome,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									52,
																									javax.swing.GroupLayout.PREFERRED_SIZE))
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																			.addGroup(
																					jPanel1Layout
																							.createParallelGroup(
																									javax.swing.GroupLayout.Alignment.LEADING,
																									false)
																							.addComponent(
																									jTextFieldEndereco)
																							.addComponent(
																									jTextFieldNome,
																									javax.swing.GroupLayout.DEFAULT_SIZE,
																									428,
																									Short.MAX_VALUE)))
															.addGroup(
																	jPanel1Layout
																			.createSequentialGroup()
																			.addComponent(
																					JlabelEmail)
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																			.addComponent(
																					jTextFieldEmail,
																					javax.swing.GroupLayout.PREFERRED_SIZE,
																					242,
																					javax.swing.GroupLayout.PREFERRED_SIZE))
															.addGroup(
																	jPanel1Layout
																			.createParallelGroup(
																					javax.swing.GroupLayout.Alignment.TRAILING)
																			.addGroup(
																					jPanel1Layout
																							.createSequentialGroup()
																							.addComponent(
																									JlabelData)
																							.addPreferredGap(
																									javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																							.addComponent(
																									jFormattedTextFieldData,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									139,
																									javax.swing.GroupLayout.PREFERRED_SIZE)
																							.addPreferredGap(
																									javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																							.addComponent(
																									JlabelTelefone)
																							.addPreferredGap(
																									javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																							.addComponent(
																									jTextFieldTelefone,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									121,
																									javax.swing.GroupLayout.PREFERRED_SIZE))
																			.addGroup(
																					jPanel1Layout
																							.createSequentialGroup()
																							.addComponent(
																									jButtonCancelar)
																							.addPreferredGap(
																									javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																							.addComponent(
																									jButtonSalvar))
																			.addComponent(
																					jTextAreaDescricao,
																					javax.swing.GroupLayout.PREFERRED_SIZE,
																					516,
																					javax.swing.GroupLayout.PREFERRED_SIZE)))
											.addContainerGap(28,
													Short.MAX_VALUE))
							.addGroup(
									javax.swing.GroupLayout.Alignment.TRAILING,
									jPanel1Layout
											.createSequentialGroup()
											.addContainerGap(210,
													Short.MAX_VALUE)
											.addComponent(
													JlabelPerfil,
													javax.swing.GroupLayout.PREFERRED_SIZE,
													276,
													javax.swing.GroupLayout.PREFERRED_SIZE)
											.addGap(207, 207, 207)));
			jPanel1Layout
					.setVerticalGroup(jPanel1Layout
							.createParallelGroup(
									javax.swing.GroupLayout.Alignment.LEADING)
							.addGroup(
									jPanel1Layout
											.createSequentialGroup()
											.addGroup(
													jPanel1Layout
															.createParallelGroup(
																	javax.swing.GroupLayout.Alignment.LEADING)
															.addGroup(
																	jPanel1Layout
																			.createSequentialGroup()
																			.addGap(
																					9,
																					9,
																					9)
																			.addComponent(
																					JlabelPerfil,
																					javax.swing.GroupLayout.PREFERRED_SIZE,
																					35,
																					javax.swing.GroupLayout.PREFERRED_SIZE)
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																			.addGroup(
																					jPanel1Layout
																							.createParallelGroup(
																									javax.swing.GroupLayout.Alignment.BASELINE)
																							.addComponent(
																									JlabelNome)
																							.addComponent(
																									jTextFieldNome,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									26,
																									javax.swing.GroupLayout.PREFERRED_SIZE))
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																			.addGroup(
																					jPanel1Layout
																							.createParallelGroup(
																									javax.swing.GroupLayout.Alignment.BASELINE)
																							.addComponent(
																									JlabelEndereço)
																							.addComponent(
																									jTextFieldEndereco,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									26,
																									javax.swing.GroupLayout.PREFERRED_SIZE))
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																			.addGroup(
																					jPanel1Layout
																							.createParallelGroup(
																									javax.swing.GroupLayout.Alignment.BASELINE)
																							.addComponent(
																									JlabelData)
																							.addComponent(
																									jFormattedTextFieldData,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									23,
																									javax.swing.GroupLayout.PREFERRED_SIZE)
																							.addComponent(
																									JlabelTelefone)
																							.addComponent(
																									jTextFieldTelefone,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									26,
																									javax.swing.GroupLayout.PREFERRED_SIZE))
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																			.addGroup(
																					jPanel1Layout
																							.createParallelGroup(
																									javax.swing.GroupLayout.Alignment.TRAILING)
																							.addComponent(
																									jTextFieldEmail,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									26,
																									javax.swing.GroupLayout.PREFERRED_SIZE)
																							.addComponent(
																									JlabelEmail))
																			.addGap(
																					1,
																					1,
																					1)
																			.addComponent(
																					JlabelDescricao)
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																			.addComponent(
																					jTextAreaDescricao,
																					javax.swing.GroupLayout.PREFERRED_SIZE,
																					128,
																					javax.swing.GroupLayout.PREFERRED_SIZE)
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																			.addGroup(
																					jPanel1Layout
																							.createParallelGroup(
																									javax.swing.GroupLayout.Alignment.BASELINE)
																							.addComponent(
																									jButtonSalvar)
																							.addComponent(
																									jButtonCancelar,
																									javax.swing.GroupLayout.PREFERRED_SIZE,
																									45,
																									javax.swing.GroupLayout.PREFERRED_SIZE)))
															.addGroup(
																	jPanel1Layout
																			.createSequentialGroup()
																			.addGap(
																					45,
																					45,
																					45)
																			.addComponent(
																					jLabelFoto,
																					javax.swing.GroupLayout.PREFERRED_SIZE,
																					164,
																					javax.swing.GroupLayout.PREFERRED_SIZE)
																			.addPreferredGap(
																					javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																			.addComponent(
																					jButtonAlterarFoto,
																					javax.swing.GroupLayout.PREFERRED_SIZE,
																					45,
																					javax.swing.GroupLayout.PREFERRED_SIZE)))
											.addContainerGap(35,
													Short.MAX_VALUE)));

			javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
					getContentPane());
			getContentPane().setLayout(layout);
			layout.setHorizontalGroup(layout.createParallelGroup(
					javax.swing.GroupLayout.Alignment.LEADING).addComponent(
					jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
			layout.setVerticalGroup(layout.createParallelGroup(
					javax.swing.GroupLayout.Alignment.LEADING).addComponent(
					jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.PREFERRED_SIZE));

			pack();
		}

		// Variables declaration - do not modify
		private javax.swing.JLabel JlabelData;
		private javax.swing.JLabel JlabelDescricao;
		private javax.swing.JLabel JlabelEmail;
		private javax.swing.JLabel JlabelEndereço;
		private javax.swing.JLabel JlabelNome;
		private javax.swing.JLabel JlabelPerfil;
		private javax.swing.JLabel JlabelPerfil1;
		private javax.swing.JLabel JlabelTelefone;
		private javax.swing.JButton jButtonAlterarFoto;
		private javax.swing.JButton jButtonCancelar;
		private javax.swing.JButton jButtonSalvar;
		private javax.swing.JFormattedTextField jFormattedTextFieldData;
		private javax.swing.JLabel jLabelFoto;
		private javax.swing.JPanel jPanel1;
		private javax.swing.JTextArea jTextAreaDescricao;
		private javax.swing.JTextField jTextFieldEmail;
		private javax.swing.JTextField jTextFieldEndereco;
		private javax.swing.JTextField jTextFieldNome;
		private javax.swing.JTextField jTextFieldTelefone;
		private JFrame EscolhaDeArquivo;
		// End of variables declaration

	}
